﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FlightClient.NewService;

namespace FlightClient
{
    
    public partial class Form2 : Form
    {
        static NewService.IFlightService flightServiceObj = new NewService.FlightServiceClient();
        Connection conn;
        int seats;
        public Form2(Connection conn, int no)
        {
            InitializeComponent();
            this.conn = conn;
            this.seats = no;
            textBox11.Text = conn.TotalPrice.ToString();
            departureTimeTextBox.Text = conn.DepartureTime.ToString();
            textBox9.Text = conn.ArrivalTime.ToString();
            textBox8.Text = conn.Flights[0].NoOfSeats.ToString();
            foreach (Flight f in conn.Flights)
            {
                ListViewItem lvl = new ListViewItem(f.FromName.ToString());
                lvl.SubItems.Add(f.ToName.ToString());
                lvl.SubItems.Add(f.DepartureTime.ToString());
                lvl.SubItems.Add(f.ArrivalTime.ToString());
                lvl.SubItems.Add(f.PriceOfTheOneSeat.ToString());
                listView2.Items.Add(lvl);
                //.SubItems.Add(c.DepartureTime);
                // , , , );

            }
        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void bookButton_Click(object sender, EventArgs e)
        {

            if (checkFields() == false)
            {
                flightServiceObj.Book(conn, seats, textBox1.Text, textBox3.Text, textBox4.Text, textBox6.Text, textBox2.Text, textBox5.Text, textBox7.Text);
                MessageBox.Show("Booking is completed", "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                this.Close();
            }

            else
            {
                MessageBox.Show("Please fill all the fields.",
        "Important Note",
        MessageBoxButtons.OK,
        MessageBoxIcon.Exclamation,
        MessageBoxDefaultButton.Button1);
            }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox11_TextChanged(object sender, EventArgs e)
        {

        }
        private Boolean checkFields()
        {
            Boolean ok = false;
            ok = String.IsNullOrEmpty(textBox1.Text);
            ok = String.IsNullOrEmpty(textBox2.Text);
            ok = String.IsNullOrEmpty(textBox3.Text);
            ok = String.IsNullOrEmpty(textBox4.Text);
            ok = String.IsNullOrEmpty(textBox5.Text);
            ok = String.IsNullOrEmpty(textBox6.Text);
            ok = String.IsNullOrEmpty(textBox7.Text);
            return ok;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
